package com.ljq.intemalcommon.dto;


import com.ljq.intemalcommon.constant.CommonStatusEnum;
import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;

/**
 * morenfanhuizhi
 */
@Data
@Accessors(chain = true)
public class ResponseResult<T> implements Serializable {
    private int code;
    private String message;
    private T data;


    /**
     *
     * @param data
     * @param <T>
     * @return
     */
    public static <T> ResponseResult success(T data){
        return new ResponseResult<>()
                .setCode(CommonStatusEnum.SUCCESS.getCode())
                .setMessage(CommonStatusEnum.SUCCESS.getValue())
                .setData(data);
    }

    /**
     *
     * @param code
     * @param message
     * @return
     */
    public static ResponseResult fail(int code,String message){
       return new ResponseResult().setCode(code)
               .setMessage(message);
    }

    /**
     *
     * @param code
     * @param message
     * @param data
     * @return
     */
    public static ResponseResult fail(int code,String message,String data){
        return new ResponseResult().setCode(code).setMessage(message).setData(data);
    }

    /**
     *
     */
    public static <T> ResponseResult fail(T data){
        return new ResponseResult<>()
                .setCode(CommonStatusEnum.FAIL.getCode())
                .setMessage(CommonStatusEnum.FAIL.getValue())
                .setData(data);
    }

}
